package com.leslie.wukong.biz.product.handler;

import com.leslie.wukong.biz.product.domain.vo.ProductVO;
import com.leslie.wukong.common.core.constants.HttpStatus;
import com.leslie.wukong.common.core.constants.ValidationConstants;
import com.leslie.wukong.common.core.domain.RestResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * ClassName: StockCheckHandler
 * Package: com.leslie.wukong.biz.product.handler
 * Description:
 * @date: 2024/12/3 18:44
 * @author: itcoder
 */
@Component
public class StockCheckHandler extends AbstractCheckHandler {
    private static final Logger log = LoggerFactory.getLogger(StockCheckHandler.class);

    @Override
    public RestResult handle(ProductVO param) {
        log.info("库存校验 Handler 开始 ....");
        boolean illegalStock = param.getStock() < 0;
        if (illegalStock) {
            return RestResult.error(HttpStatus.VALIDATION, ValidationConstants.PARAM_STOCK_ILLEGAL_ERROR);
        }
        // 其他校验逻辑
        log.info("库存校验 Handler 通过....");
        return super.next(param);
    }
}
